package com.yiren.dbaa.module.exam.view.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RadioButton;

import com.yiren.backstage.currency.enums.CarStateNameEnum;
import com.yiren.dbaa.R;
import com.yiren.dbaa.util.CarSignalUtil;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by WANGRONGXIANG
 * on 2022/2/28
 * Describe 滴驾专用车辆信号状态适配器
 */
public class DjCarSignalAdapter extends BaseAdapter {

    private Activity activity;
    private List<CarStateNameEnum> carSignalBeans;
    private int mode;

    public DjCarSignalAdapter(Activity activity, int mode) {
        this.activity = activity;
        this.mode = mode;
        carSignalBeans = CarSignalUtil.getCarSignals(activity);
    }

    @Override
    public int getCount() {
        return carSignalBeans.size();
    }

    @Override
    public Object getItem(int position) {
        return carSignalBeans.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(activity).inflate(R.layout.item_dj_car_signal, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.rbSignal.setTag(carSignalBeans.get(position).toString());
        if (mode == 1) {
            holder.rbSignal.setTextColor(activity.getResources().getColorStateList(R.color.car_signal_day_selector));
            switch (position + 1) {
                case 1:
                    CarSignalUtil.setTextDrawableLeft(activity, holder.rbSignal, R.drawable.day_signal_sc_selector);
                    break;
                case 2:
                    CarSignalUtil.setTextDrawableLeft(activity, holder.rbSignal, R.drawable.day_signal_lh_selector);
                    break;
                case 3:
                    CarSignalUtil.setTextDrawableLeft(activity, holder.rbSignal, R.drawable.day_signal_ss_selector);
                    break;
                case 4:
                    CarSignalUtil.setTextDrawableLeft(activity, holder.rbSignal, R.drawable.day_signal_jg_selector);
                    break;
                case 5:
                    CarSignalUtil.setTextDrawableLeft(activity, holder.rbSignal, R.drawable.day_signal_aqd_selector);
                    break;
                case 6:
                    CarSignalUtil.setTextDrawableLeft(activity, holder.rbSignal, R.drawable.day_signal_lb_selector);
                    break;
                case 7:
                    CarSignalUtil.setTextDrawableLeft(activity, holder.rbSignal, R.drawable.day_signal_cm_selector);
                    break;
                case 8:
                    CarSignalUtil.setTextDrawableLeft(activity, holder.rbSignal, R.drawable.day_signal_jsd_selector);
                    break;
                case 9:
                    CarSignalUtil.setTextDrawableLeft(activity, holder.rbSignal, R.drawable.day_signal_xcd_selector);
                    break;
                case 10:
                    CarSignalUtil.setTextDrawableLeft(activity, holder.rbSignal, R.drawable.day_signal_yg_selector);
                    break;
                case 11:
                    CarSignalUtil.setTextDrawableLeft(activity, holder.rbSignal, R.drawable.day_signal_zz_selector);
                    break;
                case 12:
                    CarSignalUtil.setTextDrawableLeft(activity, holder.rbSignal, R.drawable.day_signal_yz_selector);
                    break;
                case 13:
                    CarSignalUtil.setTextDrawableLeft(activity, holder.rbSignal, R.drawable.day_signal_hwd_selector);
                    break;
            }
        } else {
            holder.rbSignal.setTextColor(activity.getResources().getColorStateList(R.color.car_signal_night_selector));
            switch (position + 1) {
                case 1:
                    CarSignalUtil.setTextDrawableLeft(activity, holder.rbSignal, R.drawable.night_signal_sc_selector);
                    break;
                case 2:
                    CarSignalUtil.setTextDrawableLeft(activity, holder.rbSignal, R.drawable.night_signal_lh_selector);
                    break;
                case 3:
                    CarSignalUtil.setTextDrawableLeft(activity, holder.rbSignal, R.drawable.night_signal_ss_selector);
                    break;
                case 4:
                    CarSignalUtil.setTextDrawableLeft(activity, holder.rbSignal, R.drawable.night_signal_jg_selector);
                    break;
                case 5:
                    CarSignalUtil.setTextDrawableLeft(activity, holder.rbSignal, R.drawable.night_signal_aqd_selector);
                    break;
                case 6:
                    CarSignalUtil.setTextDrawableLeft(activity, holder.rbSignal, R.drawable.night_signal_lb_selector);
                    break;
                case 7:
                    CarSignalUtil.setTextDrawableLeft(activity, holder.rbSignal, R.drawable.night_signal_cm_selector);
                    break;
                case 8:
                    CarSignalUtil.setTextDrawableLeft(activity, holder.rbSignal, R.drawable.night_signal_jsd_selector);
                    break;
                case 9:
                    CarSignalUtil.setTextDrawableLeft(activity, holder.rbSignal, R.drawable.night_signal_xcd_selector);
                    break;
                case 10:
                    CarSignalUtil.setTextDrawableLeft(activity, holder.rbSignal, R.drawable.night_signal_yg_selector);
                    break;
                case 11:
                    CarSignalUtil.setTextDrawableLeft(activity, holder.rbSignal, R.drawable.night_signal_zz_selector);
                    break;
                case 12:
                    CarSignalUtil.setTextDrawableLeft(activity, holder.rbSignal, R.drawable.night_signal_yz_selector);
                    break;
                case 13:
                    CarSignalUtil.setTextDrawableLeft(activity, holder.rbSignal, R.drawable.night_signal_hwd_selector);
                    break;
            }
        }
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.rb_signal)
        RadioButton rbSignal;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

    public void setMode(int mode) {
        this.mode = mode;
        notifyDataSetChanged();
    }
}
